$(document).ready(function() {
	// check name availability on focus lost
	$('#user-courseref').click(function() {

	});
});

var prefix = '/spring-rest-with-ajax';

var restGet = function() {
	$.ajax({
		type : 'GET',
		url : 'home/listUserCourses',
		dataType : 'json',
		async : true,
		success : function(result) {
			alert(result);
		},
		error : function(jqXHR, textStatus, errorThrown) {
			alert(jqXHR.status + ' ' + jqXHR.responseText);
		}
	});
};

var restPut = function() {

	var JSONObject = {
		'time' : Date.now(),
		'message' : 'User PUT call !!!'
	};

	$.ajax({
		type : 'PUT',
		url : prefix + '/MyData',
		contentType : 'application/json; charset=utf-8',
		data : JSON.stringify(JSONObject),
		dataType : 'json',
		async : true,
		success : function(result) {
			alert('At ' + result.time + ': ' + result.message);
		},
		error : function(jqXHR, textStatus, errorThrown) {
			alert(jqXHR.status + ' ' + jqXHR.responseText);
		}
	});
};

var restPost = function() {
	$.ajax({
		type : 'POST',
		url : prefix + '/MyData',
		dataType : 'json',
		async : true,
		success : function(result) {
			alert('At ' + result.time + ': ' + result.message);
		},
		error : function(jqXHR, textStatus, errorThrown) {
			alert(jqXHR.status + ' ' + jqXHR.responseText);
		}
	});
};

var restDelete = function() {
	$.ajax({
		type : 'DELETE',
		url : prefix + '/MyData/' + Date.now(),
		dataType : 'json',
		async : true,
		success : function(result) {
			alert('At ' + result.time + ': ' + result.message);
		},
		error : function(jqXHR, textStatus, errorThrown) {
			alert(jqXHR.status + ' ' + jqXHR.responseText);
		}
	});
};
